<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\user_center\model\mcn;

use think\Model;

/**
 * MCN机构模型 模型
 * @package app\user_center\model
 */
class UcAttestation extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_uc_attestation';

    /**
     * 获取 机构列表数据
     * @param int $uid 用户id
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function getList(){
        $list =  self::order('create_time desc') -> paginate();
        return array_out(200, 'success', $list);
    }
    
    /**
     * 添加机构数据
     * @param int $uid 用户id
     * @param string $attestation_name 机构名称
     * @param int $user_type 类型 0普通用户 1经纪公司 2供应商
     * @param int $attestation_status 状态
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function addData($uid, $attestation_name, $user_type = 0, $attestation_status){
        $this -> uid                           = $uid;
        $this -> attestation_name              = $attestation_name;
        $this -> user_type                     = $user_type;
        $this -> attestation_status            = $attestation_status;
        $res = $this -> isUpdate(false) -> save();
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 获取 机构绑定信息
     * @param int $uid 用户id
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function getDataByUid($uid){
        $map = [];
        $map['uid'] = $uid;
        $info = self::where($map) -> find();
        if(!empty($info)){
            return array_out(200, 'success', $info);
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 艺人数增加
     * @param int $attestation_id 机构id
     * @param int $times 数量（默认1）
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function incArtistTimes($attestation_id, $times = 1){
        $map = [];
        $map['id'] = $attestation_id;
        $res = $this -> where($map) -> setInc('artist_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 艺人数增加
     * @param int $attestation_id 机构id
     * @param int $times 数量（默认1）
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function decArtistTimes($attestation_id, $times = 1){
        $map = [];
        $map['id'] = $attestation_id;
        $res = $this -> where($map) -> setDec('artist_times', $times);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }

    
}
